package com.example.vv.model.account.base;

import android.content.Context;
import android.view.View;

import com.example.vv.R;
import com.example.vv.fragmentWork.entity.ChaptersEntity;
import com.example.vv.fragmentWork.mvp.MvpFragment;
import com.example.vv.model.account.base.adapter.AvAdapter;
import com.example.vv.model.account.base.contract.AccountContract;
import com.example.vv.model.account.base.presenter.AccountPresenter;
import com.example.vv.model.accountItem.AIFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.List;

import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;

public class AccountFragment extends MvpFragment<AccountContract.View, AccountPresenter> implements AccountContract.View {

    @BindView(R.id.setup_layout)
    TabLayout setupLayout;
    @BindView(R.id.account_viewpager)
    ViewPager accountViewpager;
    AvAdapter avAdapter;
    @Override
    public int initLayout() {
        return R.layout.fragment_account;
    }

    @Override
    public AccountPresenter initPresenter() {
        return new AccountPresenter();
    }

    @Override
    public void initView() {
        avAdapter = new AvAdapter(getActivity().getSupportFragmentManager());
        accountViewpager.setAdapter(avAdapter);
        setupLayout.setSelectedTabIndicatorHeight(0);
        setupLayout.setupWithViewPager(accountViewpager);

    }

    @Override
    public void lazyLoad() {
        presenter.setChapter();
    }

    @Override
    public void initData() {

    }


    @Override
    public void doBusiness() {

    }

    @Override
    public View titleBar() {
        return null;
    }


    @Override
    public Context getMContext() {
        return getActivity();
    }

    @Override
    public void getChapter(List<ChaptersEntity> chaptersEntities) {
        List<String> list = presenter.setTitle(chaptersEntities);
        for (int i = 0; i < list.size(); i++) {
            avAdapter.addTitle(list.get(i));
            avAdapter.addFragment(new AIFragment(chaptersEntities.get(i).getId()));
        }
        accountViewpager.setOffscreenPageLimit(list.size());
    }
}